package chunmap.orm.mapping.type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import chunmap.util.ChunDaoException;

public class BlobType implements DataType {
	
	@Override
	public String toString() {
		return "blob";
	}
	
	@Override
	public Object readData(ResultSet rs, int parameterIndex) {
		try {
			return rs.getBytes(parameterIndex);
		} catch (SQLException e) {
			throw new ChunDaoException(e);
		}
	}

	@Override
	public void setPreparedStatement(PreparedStatement ps, int parameterIndex,
			Object obj) {
		try {
			if(obj==null){
				ps.setNull(parameterIndex, java.sql.Types.BLOB);
				return;
			}
			byte[] value = (byte[]) obj;
			ps.setBytes(parameterIndex, value);

		} catch (SQLException e) {
			throw new ChunDaoException(e);
		}
	}

}
